const jwt = require("jwt-simple");

const username = "laowang";
const secret = "15701665566";

//生成token
const token = jwt.encode({
  //基于一个值 生成token
  username: username,
  //token的生效时间(秒的时间戳)
  exp: Date.now() / 1000 + 5
}, secret);

//eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.//{"typ":"JWT","alg":"HS256"}(token相关信息)
//eyJ1c2VybmFtZSI6Imxhb3dhbmciLCJleHAiOjE2NTY1Nzg0NzMuOTZ9.//荷载信息({"username":"laowang","exp":1656578473.96})
//X0m4TFcjf92j0r6MlJUvFIbAeSMG-7m6E0DLxkrjrl8//加密串需要凭证(签名)(无法解码,将来拿到真正的secret值,和当前密文才能解码)

console.log(token);


//对token进行解码
setTimeout(() => {
  const re = jwt.decode(token, secret);
  console.log(re, "re");
}, 6000)